

import BaseNativeAd from "../../core/ad/BaseNativeAd";
import VivoNativeAdItemModel from "./VivoNativeAdItemModel";

/**
 * https://minigame.vivo.com.cn/documents/#/api/da/native-ad
 */
export default class VivoNativeAd extends BaseNativeAd {
    open(): void {
    }


    // protected loadFunc: Function;

    // protected errorFunc: Function;

    getItemModel() {
        return new VivoNativeAdItemModel();
    }

    create() {
        // let self = this;
        // let loadFunc = function (res: any) {
        //     self.onLoad(res)
        // }
        // let errorFunc = function (err: any) {
        //     self.onError(err)
        // }



        this.destroy();
        // if (!this.nativeAd) {
        console.log(" VivoNativeAd create", this.adUnitID)
        this.ad = this.sdk.createNativeAd({
            posId: this.adUnitID,
        });
        this.ad.onLoad(this.getFunc(this.onLoad))

        this.ad.onError(this.getFunc(this.onError))

        // }


    }

    destroy() {
        if (this.ad) {
            this.ad.offError(this.getFunc(this.onError))
            this.ad.offLoad(this.getFunc(this.onLoad))
            this.ad = null;
        }
    }
}